<?php

/**
 * SvcPHP
 *
 * Copyright (C) 2012 João Francisco Biondo Trinca
 *
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without restriction,
 * including without limitation the rights to use, copy, modify, merge,
 * publish, distribute, sublicense, and/or sell copies of the Software,
 * and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
 * IN THE SOFTWARE.
 *
 * @package    SvcPHP
 * @author     João Francisco Biondo Trinca <wolfulus@gmail.com>
 * @copyright  2012 João Francisco Biondo Trinca <wolfulus@gmail.com>
 * @license    http://www.opensource.org/licenses/mit-license.html  MIT License
 * @link       http://code.google.com/p/svcphp/
 *
 */

/**
 * Implements the request class.
 */
class Svc_Request
{
    /**
     * Stores the controller name.
     *
     * @var mixed
     */
    private $_controller;

    /**
     * Stores the action name.
     *
     * @var mixed
     */
    private $_action;

    /**
     * Constructs the request instance.
     *
     * @param mixed $controller
     * @param mixed $action
     *
     * @internal param mixed $params
     *
     * @return Svc_Request
     */
    public function __construct($controller, $action)
    {
        $this->_controller = $controller;
        $this->_action = $action;
    }

    /**
     * Gets the current action name.
     *
     * @return string
     */
    public function getActionName()
    {
        return $this->_action;
    }

    /**
     * Gets the current controller name.
     *
     * @return string
     */
    public function getControllerName()
    {
        return $this->_controller;
    }

    /**
     * Sets the current action name.
     *
     * @return string
     */
    public function setActionName($action)
    {
        $this->_action = $action;
    }

    /**
     * Sets the current controller name.
     *
     * @return string
     */
    public function setControllerName($controller)
    {
        $this->_controller = $controller;
    }

    /**
     * Gets a query value.
     *
     * @param mixed $name
     * @param mixed $default
     */
    public static function getQuery($name, $default = null)
    {
        return isset($_GET[$name]) ? $_GET[$name] : $default;
    }

    /**
     * Gets a post value.
     *
     * @param mixed $name
     * @param mixed $default
     */
    public static function getPost($name, $default = null)
    {
        return isset($_POST[$name]) ? $_POST[$name] : $default;
    }

    /**
     * Checks if the request is a post.
     *
     * @return boolean
     */
    public static function isPost()
    {
        return ($_SERVER['REQUEST_METHOD'] === 'POST');
    }
}
